package afsvctrl

import (
	"net/http"

	afsviewergomobile "gitee.com/bitwormhole/afsviewer-go-mobile"
	"github.com/starter-go/application/properties"
	"github.com/starter-go/starter"
)

// Run 以阻塞模式运行
func Run(args string, props string) int {
	r := &Runner{}
	r.Init(args, props)
	return r.Run()
}

// Start 以非阻塞模式运行
func Start(args string, props string) int {
	r := &Runner{}
	r.Init(args, props)
	return r.Start()
}

// Stop 停止运行
func Stop(args string, props string) int {
	r := &Runner{}
	r.Init(args, props)
	return r.Stop()
}

////////////////////////////////////////////////////////////////////////////////

// Runner ...
type Runner struct {
	args  []string
	props properties.Table
}

// Init ...
func (inst *Runner) Init(args string, props string) {

}

// Start 返回值：参考 http.Status
func (inst *Runner) Start() int {

	go inst.Run()

	return http.StatusOK
}

// Stop 返回值：参考 http.Status
func (inst *Runner) Stop() int {

	// todo ...

	return http.StatusOK
}

// Run 返回值：参考 http.Status
func (inst *Runner) Run() int {

	ar := []string{}
	m := afsviewergomobile.Module()
	i := starter.Init(ar)
	i.MainModule(m)
	i.WithPanic(true).Run()

	return http.StatusOK
}
